package top.yokey.learn2.acyivity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;

import com.jeremyliao.liveeventbus.LiveEventBus;

import top.yokey.learn2.MyApp;
import top.yokey.learn2.R;
import top.yokey.learn2.ToastUtil;

public class HomeFragment extends Fragment {

    private AppCompatTextView mainTextView;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        mainTextView = view.findViewById(R.id.mainTextView);
        mainTextView.setText("这是通过代码改的");

        mainTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                LiveEventBus.get("posittion)").post(4);
            }
        });
        LiveEventBus.get("test",String.class).observe(this, new Observer<String>(){

        @Override
        public void  onChanged(String s){ mainTextView.setText(s); }
    });
        return view;
    }

}
